package org.belkodevelop.geocoding.adress.json.parser;

import java.io.IOException;
import org.belkodevelop.geocoding.adress.json.GoogleAdress;
import org.belkodevelop.geocoding.adress.json.parser.exception.GoogleAdressParserException;
import org.codehaus.jackson.map.ObjectMapper;

public class GoogleAdressParser {
    
    public static GoogleAdress parse(String json) throws GoogleAdressParserException {
        ObjectMapper mapper = new ObjectMapper();
        try {
            return mapper.readValue(json, GoogleAdress.class);
        } catch (IOException ex) {
            throw new GoogleAdressParserException(ex);
        }
    }
    
    public static String toJSON(GoogleAdress googleAdress) throws GoogleAdressParserException {
        ObjectMapper mapper = new ObjectMapper();
        try {
            return mapper.writeValueAsString(googleAdress);
        } catch (IOException ex) {
            throw new GoogleAdressParserException(ex);
        }
    }
}
